package cn.hf.mychat.mapper.Impl;

import cn.hf.mychat.entity.bo.RequestUser;
import cn.hf.mychat.entity.po.TbSysUser;
import cn.hf.mychat.mapper.UserMapper;
import cn.hf.mychat.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
@RequiredArgsConstructor
public class UserServiceImpl implements UserService {

    private final UserMapper userMapper;
    @Override
    public Integer register(RequestUser requestUser) {
        TbSysUser tbSysUser = new TbSysUser();
        tbSysUser.setCreateTime(new Date());
        tbSysUser.setUpdateTime(new Date());
        BeanUtils.copyProperties(requestUser,tbSysUser);
        return userMapper.insert(tbSysUser);
    }



    @Override
    public String getUser() {
        TbSysUser tbSysUser = userMapper.selectById(1L);
        return tbSysUser.toString();
    }


    @Async
    @Override
    public void async() {
        try {
            Thread.sleep(5000);
            System.out.println("异步执行完毕");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
